﻿using System;
using System.Windows;

namespace TweeVo
{
    /// <summary>
    /// Interaction logic for AuthorizeUserDlg.xaml
    /// </summary>
    public partial class AuthorizeUserDlg : Window
    {
        public string Token { get; set; }
        public string TokenSecret { get; set; }

        public AuthorizeUserDlg()
        {
            InitializeComponent();
        }

        private void btnAuthorize_Click(object sender, RoutedEventArgs e)
        {
            oAuthTwitter oAuth = new oAuthTwitter { ConsumerKey = TwitterConst.CONSUMER_KEY, ConsumerSecret = TwitterConst.CONSUMER_SECRET };

            try
            {
                oAuth.xAuthAccessTokenGet(txtTwitterUsername.Text, txtTwitterPassword.Password);

                if (oAuth.TokenSecret.Length > 0)
                {
                    Token = oAuth.Token;
                    TokenSecret = oAuth.TokenSecret;
                    this.DialogResult = true;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error attempting to authorize username/password: " + ex.Message, "TweeVo", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
    }
}
